using System.IO;
using Common.Core;
using Microsoft.Practices.ObjectBuilder2;
using Guard=Common.Core.Guard;

namespace Common.Unity.Extensions.Serialization
{
	public class FileStreamResolver : IStreamResolver
	{
		readonly string filePath;

		public FileStreamResolver( string filePath )
		{
			Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNullOrEmpty( filePath, "filePath" );
			this.filePath = filePath;
		}

		public string FilePath
		{
			get { return filePath; }
		}

		public Stream ResolveStream( IBuilderContext context )
		{
			string filepath = Pathing.ResolvePath( FilePath );
			FileStream result = File.OpenRead( filepath );
			return result;
		}
	}
}